$(".exit").click(function(){
    $.ajax({
        type: "GET",
        url: "Logoutservlet",    
        success: function (result) {
            sessionStorage.clear();
            var link = "login.html";
            window.location.href = link;
        }
    });
})

//模态框显示及文件上传控件初始化
$("#addDataBtn").click(function () {
    closePanel();

    $("#addDataModal").modal({
        show: true,
        // backdrop:"static"
    });
    $("#gisFileUpload").fileinput("reset");
    $("#gisFileUpload").fileinput("clear");
});

$("#multiAddressShowBtn").click(function () {
    closePanel();

    $("#multiAddressModal").modal({
        show: true,
        // backdrop:"static"
    });
    $("#multiAddressFileUpload").fileinput("reset");
    $("#multiAddressFileUpload").fileinput("clear");
});

$("#cordConvertBtn").click(function () {
    closePanel();

    $("#cordConvertModal").modal({
        show: true,
        // backdrop:"static"
    });
    $("#cordFileUpload").fileinput("reset");
    $("#cordFileUpload").fileinput("clear");
});


$("#addRouteShowBtn").click(function () {
    closePanel();

    $("#addRouteModal").modal({
        show: true,
        // backdrop:"static"
    });
    $("#routeFileUpload").fileinput("reset");
    $("#routeFileUpload").fileinput("clear");
});

$("#areaCoverageShowBtn").click(function () {
    closePanel();
    $("#areaCoverageModal").modal({
        show: true,
        // backdrop:"static"
    });
    // $("#areaCoveragePanel").show();
    $("#areaCoverageFileUpload").fileinput("reset");
    $("#areaCoverageFileUpload").fileinput("clear");
});

var areaFeatureType=""
$("#heatmapShowBtn").click(function () {
    closePanel();
    areaFeatureType="heatmap"
    $("#areaFeatureModal").modal({
        show: true,
        // backdrop:"static"
    });
    // $("#areaFeaturePanel").show();
    $("#areaFeatureFileUpload").fileinput("reset");
    $("#areaFeatureFileUpload").fileinput("clear");
});

$("#clusterShowBtn").click(function () {
    closePanel();
    areaFeatureType="cluster"

    $("#areaFeatureModal").modal({
        show: true,
        // backdrop:"static"
    });
    // $("#areaFeaturePanel").show();
    $("#areaFeatureFileUpload").fileinput("reset");
    $("#areaFeatureFileUpload").fileinput("clear");
});

$("#drawDataShowBtn").click(function () {
    closePanel();
    $("#drawDataPanel").show();
});

//上传控件初始化
$("#gisFileUpload").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv', 'rar', 'zip','json'],
    // allowedPreviewType:['csv'],
    // previewFileType:['csv'],
    showPreview: false
});

$("#cordFileUpload").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv', 'rar', 'zip'],
    showPreview: false

});


$("#coordTransferFileUpload0").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv'],
    showPreview: false

});

$("#multiAddressFileUpload").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv'],
    showPreview: false

});

$("#multiAroundFileUpload").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv'],
    showPreview: false

});

$("#routeFileUpload").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv', 'rar', 'zip'],
    showPreview: false

});

$("#routeFileUpload0").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv', 'rar', 'zip'],
    showPreview: false

});

$("#routeExtentFileUpload0").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv', 'rar', 'zip'],
    showPreview: false

});

$("#routeFileUpload1").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv', 'rar', 'zip'],
    showPreview: false

});

$("#routeExtentFileUpload1").fileinput({
    language: 'zh',
    allowedFileExtensions: ['rar', 'zip'],
    showPreview: false

});

$("#areaCoverageFileUpload").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv', 'rar', 'zip'],
    showPreview: false

});

$("#areaFeatureFileUpload").fileinput({
    language: 'zh',
    allowedFileExtensions: ['xlsx', 'xls', 'csv', 'rar', 'zip'],
    showPreview: false

});

$("#fileUpload").fileinput({
    language: 'zh',
    dropZoneEnabled: false,
    showPreview: false

});


$("#addServiceBtn").click(function () {
    $("#addServiceModal").modal({
        show: true,
        // backdrop: "static"
    })
});


//控制功能面板随浏览器显示滚动条
function heightControl() {
    var height = $(this).height();
    var paneMaxHeight = height - 255 + "px";
    // var paneMaxHeight1 = height - 215 + "px";

    if (height < 750) {
        $("#termPanel").css("max-height", paneMaxHeight);
        $("#resultPanel").css("max-height", paneMaxHeight);
        // $("#routeExceptionContent").css("max-height", paneMaxHeight1);

    } else {
        $("#termPanel").css("max-height", "499px");
        $("#resultPanel").css("max-height", "499px");
        // $("#routeExceptionContent").css("max-height", "410px");

    }
}

$(window).resize(function () {
    heightControl();
});


//面板控制
var failAlert=(text)=>{
    $("#failAlert").modal({
        show: true,
        // backdrop:"static"
    });
    $("#failText").text(text);
}

var okAlert=(text)=>{
    $("#okAlert").modal({
        show: true,
        // backdrop:"static"
    });
    $("#okText").text(text);
}

var warningAlert=(text)=>{
    $("#warningAlert").modal({
        show: true,
        // backdrop:"static"
    });
    $("#warningText").text(text);
}

var infoNotify=text=>{
    $.notify({
        // options
        icon: 'glyphicon glyphicon-info-sign',
        // title: 'Bootstrap notify',
        message: text
    },{
        // settings
        element: 'body',
        position: null,
        type: "info",
        allow_dismiss: true,
        newest_on_top: false,
        showProgressbar: false,
        placement: {
            from: "top",
            align: "right"
        },
        offset: {
            x:20,
            y:200
        },
        spacing: 10,
        z_index: 1031,
        delay: 5000,
        timer: 1000,
        url_target: '_blank',
        mouse_over: null,
        animate: {
            enter: 'animated fadeInDown',
            exit: 'animated fadeOutUp'
        },
        onShow: null,
        onShown: null,
        onClose: null,
        onClosed: null,
 
    });
}

$("#coordTransferShowBtn").click(function () {
    closePanel();

    $("#coordTransferPanel").show();
});

$("#addressShowBtn").click(function () {
    closePanel();
    
    $("#addressPanel").show();
    let title = $("#addressSearchTitle").text();
    // title = title.replace(/道路区间检索/g, "地址检索");
    $("#addressSearchLabel").text("请输入要检索地址的关键字");
    $("#addressSearchTitle").text("地址检索");
});

$("#addressPanel .close").click(function () {
    closePanel();
});

$("#addressInfoPanel .close").click(function () {
    map.infoWindow.clearFeatures();
    $("#addressInfoPanel").hide();
});


$("#aroundShowBtn").click(function () {
    closePanel();
    measurementFlag = true;

    closeIdentify();
    $("#aroundPanel").show();
});

// $("#aroundPanel .close").click(function () {
//     closePanel();

// });


$("#multiAroundShowBtn").click(function () {
    closePanel();
    $("#multiAroundFileUpload").fileinput("reset");
    $("#multiAroundFileUpload").fileinput("clear");

    $("#multiAroundPanel").show();
});

$("#roadSearchShowBtn").click(function () {
    closePanel();

    const zTree = $.fn.zTree.getZTreeObj("layerList");

    const node = zTree.getNodeByParam("id", roadLayerId);
    if (node != null && !node.checked) {
        zTree.checkNode(node, true, true, true);
    }
    $("#addressPanel").show();
    let title = $("#addressSearchTitle").text();

    $("#addressSearchLabel").text("请输入要检索的道路名或道路交叉口名");
    $("#addressSearchTitle").text("道路区间检索");
});


$("#addressPanel .close").click(function () {
    closePanel();
    if ($("#addressSearchTitle").text() == "道路区间检索") {
        closeRoadLayer();
    }
});

$("#xyLocationShowBtn").click(function () {
    closePanel();

    $("#xyLocationPanel").show();
});


$("#xyLocationPanel .close").click(function () {
    closePanel();
});

$("#imageCompareShowBtn").click(function () {
    // $("#imageComparePanel").css("height", 400);
    $("#imageCompareRow2").show();

    closePanel();

    measurementFlag = true;

    closeIdentify();

    $("#imageComparePanel").show();
});

// $("#imageComparePanel .close").click(function () {
//     closePanel();
//     imageCompareReset();
//     compareMapsReset();
// });

$("#changeDetectionShowBtn").click(function () {
    closePanel();

    $("#changeDetectionPanel").show();
});

$("#changeDetectionPanel .close").click(function () {
    closePanel();
});

$("#routeExceptionShowBtn").click(function () {
    closePanel();

    $("#routeExceptionPanel").show();
    $("#timeLimitInput").val("3");
});


$(".close").click(function () {
    closePanel();
});


function closePanel() {
    menpai = false;
    bufferCircle = null;
    isCtxMenu=false;
    
    thematicGraphicLayer.clear();
    aroundGraphicLayer.clear();
    bufferGraphicsLayer.clear();
    exceptionGraphicsLayer.clear();

    map.infoWindow.hide();


    $(":input.form-control").val("");
    $(".searchPanel").hide();
    $("#measurePanel").hide();
    $("#addressInfoPanel").hide();

    $("#aroundPage").empty();
    $("#addressList>ul").empty();
    $("#featureList ul").empty();
    $("#aroundList ul").empty();
    $("#resultPanel ul.row").empty();
    $("#buildingCorpList ul").empty();
    $("#resultPanel ul.row").empty();

    $("#addressPanel .close").show();
    $("#addressPanel .back").hide();
    
    $("#addressPanel").hide();
    $("#addressPanel input").val("");
    $("#addressPage").empty();
    $("#addressList>ul").empty();

    $("#aroundPanel").hide();

    $("#featureList ul").empty();
    $("#aroundList ul").empty();
    $("#resultPanel ul.row").empty();
    $("#buildingCorpList ul").empty();
    $("#resultPanel ul.row").empty();
    $("#xyLocationPanel").hide();
    $("#imageComparePanel").hide();
    $("#areaCoveragePanel").hide();
    $("#attrCalPanel").hide();
    $("#changeDetectionPanel").hide();
    $("#routeExceptionPanel").hide();
    // $("#areaCoveragePanel").hide();
    $("#areaFeaturePanel").hide();
    $("#coordTransferPanel").hide();
    $("#multiAroundPanel").hide();
    $("#roadSearchPanel").hide();
    $("#gAroundPanel").hide();
    $("#drawDataPanel").hide();

    // map.graphics.clear();

    $("#mainMap").show();
    $("#compareMap").hide();
    imageCompareReset();
    compareMapsReset();
    drawDataToolbar.deactivate();
    drawGraphicsLayer.clear();


    measurementFlag = false;
    openIdentify();

    // if (measurement) {
    //     measurement.destroy();
    //     // measurement.setTool("area",false);
    //     // measurement.setTool("length",false);
    //     measurementFlag = false;
    //     openIndentify();
    // }



}


$("#menu-list a").bind("click", function () {
    $("#menu-list a").removeClass("active");
    $(this).addClass("active");
});

function closeRoadLayer() {
    console.log('777');
    const zTree = $.fn.zTree.getZTreeObj("layerList");
    const node = zTree.getNodeByParam("id", roadLayerId);
    if (node.checked) {
        zTree.checkNode(node, false, true, true);
    }
}
